﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Public;
using BLL;

namespace QLNhanKhau
{
    public partial class frmDangNhap : Form
    {
        public static NguoiDungPublic user_login = new NguoiDungPublic();


        public frmDangNhap()
        {
            InitializeComponent();
        }

        private void frmDangNhap_Load(object sender, EventArgs e)
        {
            // remove it
            txtTenDangNhap.Text = "nvan";
            txtMatKhau.Text = "123";
         //   btnDangNhap_Click(sender,e);
        }

        
        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            NguoiDungPublic nd = new NguoiDungPublic();
            nd.TenDangNhap = txtTenDangNhap.Text;
            nd.MatKhau = DungChung.md5(txtMatKhau.Text);
            string message = "";
            if (NguoiDungBLL.KiemTraDangNhap(nd.TenDangNhap, nd.MatKhau, ref user_login, ref message) == true)
            {
              
                frmMenu fm = new frmMenu();
                fm.Show();
                this.Hide() ;
                if (ThietLapBLL.TestThietLap() == true)
                {
                    frmThietLap tl = new frmThietLap();
                    tl.ShowDialog();
                }
            }
            else
            {
                labLoiDangNhap.Text = message;
                txtTenDangNhap.Text = "";
                txtMatKhau.Text = "";
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void txtTenDangNhap_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (txtTenDangNhap.Text.Length > 14 && !Char.IsControl(e.KeyChar)||e.KeyChar==13)
            {
                e.Handled = true;
            }
            if (e.KeyChar ==13)
                btnDangNhap_Click(sender, e);
        }

        private void txtMatKhau_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (txtMatKhau.Text.Length > 30 && !Char.IsControl(e.KeyChar)||e.KeyChar==13)
            {
                e.Handled = true;
            }
            if (e.KeyChar == 13)
                btnDangNhap_Click(sender, e);
        }

        
    }
}
